package com.cencat.framework.core.util;

public class TenantContextHolder {
    
    private static final ThreadLocal<TenantContext> CONTEXT_HOLDER = new ThreadLocal<>();
    
    public static void setTenantContext(TenantContext context) {
        CONTEXT_HOLDER.set(context);
    }
    
    public static TenantContext getTenantContext() {
        return CONTEXT_HOLDER.get();
    }
    
    public static Long getCurrentTenantId() {
        TenantContext context = CONTEXT_HOLDER.get();
        return context != null ? context.getTenantId() : null;
    }
    
    public static String getCurrentTenantCode() {
        TenantContext context = CONTEXT_HOLDER.get();
        return context != null ? context.getTenantCode() : null;
    }
    
    public static void clear() {
        CONTEXT_HOLDER.remove();
    }
    
    public static class TenantContext {
        private Long tenantId;
        private String tenantCode;
        
        public Long getTenantId() {
            return tenantId;
        }
        
        public void setTenantId(Long tenantId) {
            this.tenantId = tenantId;
        }
        
        public String getTenantCode() {
            return tenantCode;
        }
        
        public void setTenantCode(String tenantCode) {
            this.tenantCode = tenantCode;
        }
    }
}